package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.app.entity.BsDepartEntity;
import io.renren.modules.app.entity.BsPostEntity;
import io.renren.modules.app.service.BsPostService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;





/**
 * 岗位表
 *
 */
@RestController
@RequestMapping("tb_bs_post/bspost")
public class BsPostController {
    @Autowired
    private BsPostService bsPostService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("tb_bs_post:bspost:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bsPostService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{postId}")
    @RequiresPermissions("tb_bs_post:bspost:info")
    public R info(@PathVariable("postId") Long postId){
		BsPostEntity bsPost = bsPostService.getById(postId);

        return R.ok().put("bsPost", bsPost);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("tb_bs_post:bspost:save")
    public R save(@RequestBody BsPostEntity bsPost){
		bsPostService.save(bsPost);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("tb_bs_post:bspost:update")
    public R update(@RequestBody BsPostEntity bsPost){
		bsPostService.updateById(bsPost);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("tb_bs_post:bspost:delete")
    public R delete(@RequestBody Long[] postIds){
		bsPostService.removeByIds(Arrays.asList(postIds));

        return R.ok();
    }

    /**
     * 部门下拉列表获取
     * @return
     */
    @RequestMapping("/getDepart")
    public R getDepart(){
        List<BsDepartEntity> list = bsPostService.getDepart();
        return R.ok(list);
    }


}
